package com.umpay.util;

/**
 * 
 * 隐秘数据工具类
 * 
 */
public class HideDataUtil {

	public static String hideSensitiveData(String data, int beforeLength, int afterLength) {
		if (StringUtils.isEmpty(StringUtils.trim(data))) {
			return data;
		}
		int length = data.length();
		if(length < beforeLength || length <= (beforeLength + afterLength)) {
			return data;
		}
		// 替换字符串，当前使用“*”
		String replaceSymbol = "*";
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			if (i < beforeLength || i >= (length - afterLength)) {
				sb.append(data.charAt(i));
			} else {
				sb.append(replaceSymbol);
			}
		}

		return sb.toString();
	}
	
}
